package com.example.algorithm.hash;

/**
 * @author : zhy
 * @since : 2022/7/24
 * 救赎信，和有效异构字符串差不多
 */
public class Ransom {

    public boolean canConstruct(String ransomNote, String magazine) {
        int len1 = ransomNote.length();
        int len2 = magazine.length();
        if(len1>len2){
            return false;
        }
        char[] mage = magazine.toCharArray();
        char[] ran = ransomNote.toCharArray();
        int []result=new int[26];
        for(char c:mage)
        {
            result[c-'a']++;
        }
        for(char c:ran)
        {
            result[c-'a']--;
        }
        for(int i:result)
        {
            if(i<0){
                return false;
            }
        }
        return true;
    }


    public static void main(String[] args) {

    }
}
